#    This file is part of robo-ircbot.
#
#    robo-ircbot is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    robo-ircbot is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with robo-ircbot.  If not, see <http://www.gnu.org/licenses/>.

package Robo::Event;
use strict;
use warnings;

# Constructor
sub new
{
        my ($class, %opts) = @_;
        
        my $sock = $opts{sock} || undef;
        my $cfg = $opts{cfg} || undef;
        my $robo = $opts{robo} || undef;
        my $from = $opts{from} || undef;
        my $to = $opts{to} || undef;
        my $data = $opts{data} || undef;
        my $raw = $opts{raw} || undef;
        my $knick = $opts{knick} || undef;
        my $nolog = $opts{nolog} || undef;
        
        my $self = {
                _sock => $sock,
                _cfg => $cfg,
                _robo => $robo,
                _from => $from,
                _to => $to,
                _data => $data,
                _raw => $raw,
                _knick => $knick,
                _nolog => $nolog,
        };        
        
        bless($self);
        return $self;
}

# Send data to connection socket.
sub s
{
        my ($self, $send) = @_;
        
        if ($self->{_sock}) {
                print {$self->{_sock}} $send."\r\n";
        }
}

# Destination (send to a channel or specific nick)
sub dest
{
        my $self = shift;
        
        return undef unless ($self->{_to} && $self->{_from});
        
        if ($self->{_to} =~ /^\#.+/) {
                return $self->{_to};
        }
        
        $self->{_from} =~ /(.+)!.+/;
        return $1;
}

# Sock get/set.
sub sock
{
        my ($self, $sock) = @_;
        
        if ($sock) { $self->{_sock} = $sock; }
        else { return $self->{_sock}; }
}

# Cfg get/set.
sub cfg
{
        my ($self, $cfg) = @_;
        
        if ($cfg) { $self->{_cfg} = $cfg; }
        else { return $self->{_cfg}; }
}

# Robo get/set.
sub robo
{
        my ($self, $robo) = @_;
        
        if ($robo) { $self->{_robo} = $robo; }
        else { return $self->{_robo}; }
}

# From get/set.
sub from
{
        my ($self, $from) = @_;
        
        if ($from) { $self->{_from} = $from; }
        else { return $self->{_from}; }
}

# To get/set.
sub to
{
        my ($self, $to) = @_;
        
        if ($to) { $self->{_to} = $to; }
        else { return $self->{_to}; }
}

# Data get/set.
sub data
{
        my ($self, $data) = @_;
        
        if ($data) { $self->{_data} = $data; }
        else { return $self->{_data}; }
}

# Raw get/set.
sub raw
{
        my ($self, $raw) = @_;
        
        if ($raw) { $self->{_raw} = $raw; }
        else { return $self->{_raw}; }
}

# Knick get/set.
sub knick
{
        my ($self, $knick) = @_;
        
        if ($knick) { $self->{_knick} = $knick; }
        else { return $self->{_knick}; }
}

# Nolog get/set.
sub nolog
{
        my ($self, $nolog) = @_;
        
        if ($nolog) { $self->{_nolog} = $nolog; }
        else { return $self->{_nolog}; }
}

1;
